// source --> http://beunlike.com/wp-content/plugins/tapatalk/smartbanner/appbanner.js
//add document ready function
var add_app_event = function(fn){
if(document.addEventListener){
document.addEventListener("DOMContentLoaded",function(){
document.removeEventListener("DOMContentLoaded",arguments.callee,false);
fn();
},false);
}
}
// ---- params check ----
if (typeof(app_api_key) == "undefined") var app_api_key = '';
if (typeof(app_ios_id) == "undefined") var app_ios_id = '';
if (typeof(app_android_id) == "undefined") var app_android_id = '';
if (typeof(app_kindle_url) == "undefined") var app_kindle_url = '';
if (typeof(is_byo) == "undefined") var is_byo = 0;
if (typeof(tapatalk_dir_name) == "undefined") var tapatalk_dir_name = 'mobiquo';
if (typeof(app_forum_name) == "undefined" || !app_forum_name)
{
var app_forum_name = "this forum";
}
if (typeof(app_location_url) == "undefined" || !app_location_url) var app_location_url = "tapatalk://";
var app_deep_link = app_location_url.replace('tapatalk://', '');
// ---- smartbanner display start----
// make sure all variables are defined
if (typeof(is_mobile_skin) == "undefined") var is_mobile_skin = false;
if (typeof(app_board_url) == "undefined") var app_board_url = '';
if (typeof(app_banner_message) == "undefined" || !app_banner_message) var app_banner_message = "Follow {your_forum_name}
with {app_name} for [os_platform]";
if (typeof(app_banner_view_button) == "undefined" || !app_banner_view_button) var app_banner_view_button = "VIEW";
var app_location_url_byo = app_location_url.replace('tapatalk://', 'tapatalk-byo://');
// set default iOS app for native smart banner
var app_ios_id_default = '307880732'; // Tapatalk Free, 585178888 for Tapatalk Pro
var app_ios_hd_id_default = '307880732'; // Tapatalk Free, 481579541 for Tapatalk HD
// Support native iOS Smartbanner
var native_ios_banner = false;
if (app_ios_id != '-1' && navigator.userAgent.match(/Safari/i) != null && (typeof(app_banner_enable) == "undefined" || app_banner_enable) &&
(navigator.userAgent.match(/CriOS/i) == null && window.Number(navigator.userAgent.substr(navigator.userAgent.indexOf('OS ') + 3, 3).replace('_', '.')) >= 6))
{
banner_location_url = app_ios_id ? app_location_url_byo : app_location_url;
if (navigator.userAgent.match(/iPad/i) != null)
{
document.write('');
native_ios_banner = true;
}
else if (navigator.userAgent.match(/iPod|iPhone/i) != null)
{
document.write('');
native_ios_banner = true;
}
}
// initialize app download url
if (is_byo)
{
var app_install_url = 'https://tapatalk.com/m/?id=6';
if (app_ios_id) app_install_url = app_install_url+'&app_ios_id='+app_ios_id;
if (app_android_id) app_install_url = app_install_url+'&app_android_id='+app_android_id;
if (app_kindle_url) app_install_url = app_install_url+'&app_kindle_url='+app_kindle_url;
if (app_board_url) app_install_url = app_install_url+'&referer='+app_board_url;
}
else
var app_install_url = 'https://tapatalk.com/m/?id=6&referer='+encodeURIComponent(app_deep_link);
// for those forum system which can not add js in html body
add_app_event(tapatalkDetectAfterLoad)
var bannerLoaded = false
var bannerScale
var bannerHeight
var tapatalk_logo_height
function tapatalkDetectAfterLoad()
{
tapatalkDetect(true)
}
function tapatalkDetect(afterLoad)
{
if(bannerLoaded) return;
var standalone = navigator.standalone // Check if it's already a standalone web app or running within a web ui view of an app (not mobile safari)
var is_android = false;
var is_ios = false;
var is_wp = false;
// work only when browser support cookie
if (!navigator.cookieEnabled
|| (typeof(app_banner_enable) !== "undefined" && !app_banner_enable)
|| bannerLoaded
|| standalone
|| document.cookie.indexOf("banner-closed=true") >= 0
|| native_ios_banner)
return
bannerLoaded = true
getBannerScale();
if(window.screen.width < 600 && app_forum_name.length > 20)
{
app_forum_name = "this forum";
}
else if(app_forum_name.length > 40 && window.screen.width >= 600)
{
app_forum_name = app_forum_name.substr(0,40) + "...";
}
app_banner_message = app_banner_message.replace(/\{your_forum_name\}/gi, app_forum_name);
app_banner_message = app_banner_message.replace(/\{app_name\}/gi, "Tapatalk");
if (navigator.userAgent.match(/iPhone|iPod/i)) {
if (app_ios_id == '-1') return;
app_banner_message = app_banner_message.replace(/\[os_platform\]/gi, 'iPhone');
banner_location_url = app_ios_id ? app_location_url_byo : app_location_url;
is_ios = true;
}
else if (navigator.userAgent.match(/iPad/i)) {
if (app_ios_id == '-1') return;
app_banner_message = app_banner_message.replace(/\[os_platform\]/gi, 'iPad');
banner_location_url = app_ios_id ? app_location_url_byo : app_location_url;
is_ios = true;
}
else if (navigator.userAgent.match(/Silk|KFOT|KFTT|KFJWI|KFJWA/)) {
if (app_kindle_url == '-1') return;
app_banner_message = app_banner_message.replace(/\[os_platform\]/gi, 'Kindle');
banner_location_url = app_kindle_url ? app_location_url_byo : app_location_url;
}
else if (navigator.userAgent.match(/Android/i)) {
if (app_android_id == '-1') return;
app_banner_message = app_banner_message.replace(/\[os_platform\]/gi, 'Android');
banner_location_url = app_android_id ? app_location_url_byo : app_location_url;
is_android = true;
}
else if (navigator.userAgent.match(/IEMobile|Windows Phone/i)) {
if (app_ios_id || app_android_id || app_kindle_url) return;
app_banner_message = app_banner_message.replace(/\[os_platform\]/gi, 'Windows Phone');
banner_location_url = app_location_url;
is_wp = true;
}
else
return
//init css style
if (app_board_url == '') app_board_url = '.';
tapatalk_link = document.createElement( "link" );
tapatalk_link.href = app_board_url + '/' + tapatalk_dir_name + '/smartbanner/appbanner.css';
tapatalk_link.type = "text/css";
tapatalk_link.rel = "stylesheet";
document.getElementsByTagName("head")[0].appendChild(tapatalk_link);
style_mobile_banner = 'position:fixed;margin:0;padding:0;top:0;left:0;right:0;width:100%;font-size:1em;z-index:2147483647;color:#000000; background-color: #f2f2f2;text-align:left;';
style_mobile_banner_heading = 'font-size:1.75em;padding:0;line-height:1.3em;margin:0;text-align:left;color:#000000;';
style_mobile_banner_heading_android = style_mobile_banner_heading + 'font-family: Roboto;font-weight:normal;';
style_mobile_banner_heading_ios = style_mobile_banner_heading + 'font-family: Helvetica;font-weight:normal;';
style_mobile_banner_app_desc = 'font-family: Roboto;font-size:1.75em;font-weight:300;color:#000000;';
style_mobile_banner_app_desc_ios = style_mobile_banner_app_desc + 'font-family: Helvetica;font-size:1.75em;font-weight:300;color:#000000;'
style_mobile_banner_open = 'background-color:#32c7e7;color:#ffffff;font-family: Roboto;';
style_mobile_banner_open_ios = 'background-color:#f2f2f2;color:#007aff;font-family: Helvetica;border:1px solid #007aff;';
bodyItem = document.body
appBanner = document.createElement("div")
appBanner.id = "tt_mobile_banner"
if(is_android)
{
//class_ext = '_android';
app_desc = 'FREE - on Google Play';
var css = '@import url(https://fonts.googleapis.com/css?family=Roboto:100,100italic,300,300italic,400,400italic,500,500italic,700,700italic,900,900italic&subset=latin,latin-ext,cyrillic,cyrillic-ext,greek-ext,greek,vietnamese);' +
'@import url(https://fonts.googleapis.com/css?family=Roboto+Condensed:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext,cyrillic-ext,cyrillic,greek-ext,greek,vietnamese);' +
'@import url(https://fonts.googleapis.com/css?family=Roboto+Slab:400,100,300,700&subset=latin,latin-ext,greek-ext,greek,vietnamese,cyrillic,cyrillic-ext);';
tapatalk_style = document.createElement('style');
tapatalk_head = document.head || document.getElementsByTagName('head')[0],
tapatalk_style.type = 'text/css';
if (tapatalk_style.styleSheet) {
tapatalk_style.styleSheet.cssText = css;
} else {
tapatalk_style.appendChild(document.createTextNode(css));
}
tapatalk_head.appendChild(tapatalk_style);
style_mobile_banner_heading = style_mobile_banner_heading_android
}
else if(is_ios)
{
//class_ext = '_ios';
app_desc = 'FREE - on App Store';
style_mobile_banner_heading = style_mobile_banner_heading_ios;
style_mobile_banner_app_desc = style_mobile_banner_app_desc_ios;
style_mobile_banner_open = style_mobile_banner_open_ios;
}
else if(is_wp)
{
//class_ext = '_wp';
app_desc = 'FREE - on WP App Store';
}
else
{
//class_ext = ''
}
appBanner.className = 'mobile_banner_tt';
appBanner.style = style_mobile_banner;
if(!isMobileStyle())
{
tapatalk_logo_height = 8 * 8 * bannerScale;
appBanner.innerHTML =
'
' +
''+
' ' +
' | ' +
' | ' +
'' +
'' +
' | ' +
' | ' +
'' +
'' +
''+
'' +
' '+app_banner_message+' '+
' | '+
' ' +
''+
'' +
''+
' | '+
' ' +
''+
'' +
' '+app_desc+' '+
' | '+
' ' +
' ' +
' | ' +
' | ' +
'' +
''+ app_banner_view_button +''+
' | ' +
' | ' +
'
' +
'
';
bannerHeight = tapatalk_logo_height + 3 * 8 * bannerScale;
}
else
{
tapatalk_logo_height = 8 * 8 * bannerScale * 0.67;
bannerHeight = tapatalk_logo_height + 1.5 * 8 * bannerScale;
appBanner.innerHTML =
'' +
''+
' ' +
' | ' +
' | ' +
'' +
'' +
' | ' +
' | ' +
'' +
'' +
''+
'' +
' '+app_banner_message+' '+
' | '+
' ' +
''+
'' +
''+
' | '+
' ' +
''+
'' +
' '+app_desc+' '+
' | '+
' ' +
' ' +
' | ' +
' | ' +
'' +
''+ app_banner_view_button +''+
' | ' +
' | ' +
'
' +
'
';
}
bodyItem.insertBefore(appBanner, bodyItem.firstChild)
setFontSize(1)
resetBannerStyle();
if(navigator.userAgent.match(/chrome/i) && is_android)
{
open_or_install_button = document.getElementById("mobile_banner_open");
version = parseInt(window.navigator.appVersion.match(/Chrome\/(\d+)\./i)[1], 10);
if(version > 25)
{
// banner_location_url = "intent://scan/#Intent;scheme=" + banner_location_url + ";package=com.quoord.tapatalkpro.activity;end";
banner_location_url = banner_location_url.replace(/^tapatalk:\/\//i, '');
banner_location_url = "intent://" + banner_location_url + "#Intent;scheme=tapatalk;package=com.quoord.tapatalkpro.activity;end";
open_or_install_button.href = banner_location_url;
}
}
//Detect whether device supports orientationchange event, otherwise fall back to
var supportsOrientationChange = "onorientationchange" in window,
orientationEvent = supportsOrientationChange ? "orientationchange" : "resize";
window.addEventListener(orientationEvent, function() {
getBannerScale();
tapatalk_logo_height = 8 * 8 * bannerScale;
setFontSize(1);
bannerLogo = document.getElementById("mobile_banner_logo_img");
bannerDiv = document.getElementById("banner_div_empty");
bannerLogo.style.height = tapatalk_logo_height + 'px';
bannerHeight = appBanner.clientHeight;
bannerDiv.style.height = bannerHeight + "px";
});
if (typeof onTapatalkBannerShow == 'function') {
onTapatalkBannerShow();
}
}
function setFontSize(Scale)
{
if (bannerScale > 1) {
appBanner.style.fontSize = (8*bannerScale*Scale)+"px";
tables = appBanner.getElementsByTagName("table");
for(var i=0;i < tables.length;i++){
table = tables[i];
table.style.fontSize = (8*bannerScale*Scale)+"px";
tds = table.getElementsByTagName("td");
for(var j=0;j < tds.length;j++){
tds[j].style.fontSize = (8*bannerScale*Scale)+"px";
}
}
}
}
function getBannerScale()
{
bannerScale = document.body.clientWidth / window.screen.width
if(bannerScale == 1 || isMobileStyle())
{
bannerScale = 1.5;
return;
}
if (bannerScale < 1.5 || (is_mobile_skin && navigator.userAgent.match(/mobile/i))) bannerScale = 1.5;
// mobile portrait mode may need bigger scale
if (window.innerWidth < window.innerHeight)
{
if (bannerScale < 2.0 && !is_mobile_skin && document.body.clientWidth > 600) {
bannerScale = 1.5
}
else if(bannerScale < 2.5) {
bannerScale = 2.0
}
}
else
{
if (navigator.userAgent.match(/mobile/i) && bannerScale < 1.5 && !is_mobile_skin && document.body.clientWidth > 600) {
bannerScale = 1.5
}
}
if(bannerScale > 2.5) bannerScale = 2.5;
}
function isMobileStyle()
{
/*check if is mobile style*/
metas = document.getElementsByTagName( "meta" );
var is_mobile_style = false
for(i = 0; i < metas.length; i++)
{
if(metas[i].name && metas[i].name.toLowerCase() == 'viewport' )
{
meta_content = metas[i].content;
re = /width\s?=\s?device\-width/i;
if((re.test(meta_content)))
{
is_mobile_style = true;
}
}
}
if(document.body.clientWidth < 600)
{
is_mobile_style = true;
}
return is_mobile_style;
}
function openOrInstall()
{
iframe = document.createElement("iframe");
iframe.id = 'open_in_app';
document.body.insertBefore(iframe, bodyItem.firstChild);
iframe.style.display = "none";
iframe.src = banner_location_url;
setTimeout(function(){
window.location.href = app_install_url;
},1);
}
function resetBannerTop()
{
if (getComputedStyle(bodyItem, null).position !== 'static' || document.getElementById('google_translate_element'))
appBanner.style.top = '-'+bannerTop
}
function closeBanner()
{
bannerDiv = document.getElementById("banner_div_empty");
bodyItem.removeChild( appBanner );
bodyItem.removeChild( bannerDiv );
setBannerCookies('banner-closed', 'true', 90);
if (typeof onTapatalkBannerClosed == 'function') {
onTapatalkBannerClosed();
}
}
function setBannerCookies(name, value, exdays)
{
var exdate = new Date();
exdate.setDate(exdate.getDate()+exdays);
value=escape(value)+((exdays==null)?'':'; expires='+exdate.toUTCString());
document.cookie=name+'='+value+'; path=/;';
}
add_app_event(gestureChangeListener);
function gestureChangeListener()
{
appBanner = document.getElementById("tt_mobile_banner");
if(appBanner == undefined)
{
return;
}
document.addEventListener("touchmove", touchMove, false);
document.addEventListener("touchend", touchEnd, false);
touchEnd();
}
function touchMove()
{
touchEnd();
}
function touchEnd()
{
resetBannerStyle();
}
function resetBannerStyle()
{
appBanner = document.getElementById("tt_mobile_banner");
if(appBanner == undefined)
{
return;
}
Scale = window.innerWidth / document.body.clientWidth ;
if(Scale > 1)
{
Scale = 1;
}
setFontSize(Scale);
newBannerHeight = bannerHeight * Scale;
bannerDiv = document.getElementById("banner_div_empty");
bannerLogo = document.getElementById("mobile_banner_logo_img");
bannerLogo.style.height = tapatalk_logo_height * Scale + 'px';
if(bannerDiv == undefined)
{
bannerDiv = document.createElement("div");
bannerDiv.style.margin = 0;
bannerDiv.style.padding = 0;
bannerDiv.id = "banner_div_empty";
document.body.insertBefore(bannerDiv, bodyItem.firstChild);
}
bannerDiv.style.height = newBannerHeight + "px";
};